import { createSlice } from "@reduxjs/toolkit";
import { Toast } from "antd-mobile";

export const TickpersonSlice = createSlice({
  name: "TickpersonSlice",
  initialState: {
    TickList: [
      {
        id: 1,
        name: "南平公主",
        code: "3784597281658972873",
        state: false,
      },
      {
        id: 2,
        name: "上官若雨",
        code: "2637897281658972873",
        state: false,
      },
      {
        id: 3,
        name: "光明的守候",
        code: "9866597281658972873",
        state: false,
      },
      {
        id: 4,
        name: "炽热支配者",
        code: "6372897281658972873",
        state: false,
      },
    ],
  },
  reducers: {
    addTick(state, { payload }) {
      const item = state.TickList.find((item) => item.id === payload.id);
      if (!item) {
        state.TickList.push(payload);
        Toast.show({
          icon: "success",
          content: "添加成功",
          duration: 1000,
        });
      } else {
        Toast.show({
          icon: "fail",
          content: "已有此人",
          duration: 1000,
        });
      }
    },
  },
});

// Action creators are generated for each case reducer function
export const { addTick } = TickpersonSlice.actions;

export default TickpersonSlice.reducer;
